from database import *


# 定义表
class Student(Base):
    __tablename__ = 'student'
    id = Column(Integer, primary_key=True)
    name = Column(String(100))
    age = Column(Integer)
    address = Column(String(100))

# 定义插入数据
student1 = Student(id=1001, name='ling', age=25, address="beijing")
student2 = Student(id=1002, name='molin', age=18, address="jiangxi")
student3 = Student(id=1003, name='karl', age=16, address="suzhou")

# 插入数据
session.add_all([student1, student2, student3])

# 查询数据
my_stdent = session.query(Student).filter_by(name="ling").first()
print(my_stdent.address)

# 提交
session.commit()
session.close()
